package link.cocoon.finance.util;

import java.math.BigDecimal;
import java.time.LocalDate;
import link.cocoon.finance.util.AnnualReportInfo.AnnualReportItem;

/**
 * @author Cocoon
 * @date 2020/4/8  15:05
 */
public class MillionaireUtil {

  public static void getAnnualReportInfo(AnnualReportInfo annualReportInfo) {
    int nowYear = LocalDate.now().getYear();

    int year = annualReportInfo.getDeadlineYear() - nowYear;
    BigDecimal doubleNowIncome = BigDecimal.valueOf(annualReportInfo.getNowIncome());
    BigDecimal targetIncome = BigDecimal.valueOf(annualReportInfo.getTargetIncome());
    BigDecimal multiple = targetIncome.divide(doubleNowIncome, 10, BigDecimal.ROUND_HALF_UP);
    BigDecimal sumYears = new BigDecimal("1.0").divide(BigDecimal.valueOf(year), 10, BigDecimal.ROUND_HALF_UP);
    double step = Math.pow(multiple.doubleValue(), sumYears.doubleValue());
    for (int i = 1; i <= year; i++) {
      doubleNowIncome = doubleNowIncome.multiply(BigDecimal.valueOf(step));
      annualReportInfo.getAnnualReport().add(new AnnualReportItem(nowYear + i + "", doubleNowIncome.longValue()));
    }
    annualReportInfo.setNowYear(nowYear);
    annualReportInfo.setStep(step);
  }

}
